<template>
	<view class="mechanismWorking">
		<f-navbar title="人员维保（维保）" :iconLeft="true" :isBack="true" @goBack="goBack" />
		<view class="mechanismWorking-header">
			<view class="mechanismWorking-header-box ff-border-radius-10 ff-bg-fff">
				<view class="ff-font-16 ff-font-weight-600 ff-color-000 ff-margin-bottom-5 ff-line-height-1-3">
					{{ maintenanceDetails.projectName }}
				</view>
				<view class="ff-align-items-one ff-flex-wrap">
					<view class="ff-margin-right-10 ff-font-12">
						<view v-if="maintenanceDetails.projectStatus == 0" class="tips1">项目状态&nbsp;|&nbsp;已发布</view>
						<view v-if="maintenanceDetails.projectStatus == 1" class="tips1">项目状态&nbsp;|&nbsp;已响应</view>
						<view v-if="maintenanceDetails.projectStatus == 2" class="tips1">项目状态&nbsp;|&nbsp;已确认</view>
						<view v-if="maintenanceDetails.projectStatus == 3" class="tips1">项目状态&nbsp;|&nbsp;进行中</view>
						<view v-if="maintenanceDetails.projectStatus == 4" class="tips1">项目状态&nbsp;|&nbsp;已结束</view>
						<view v-if="maintenanceDetails.projectStatus == 5" class="tips1">项目状态&nbsp;|&nbsp;待批准</view>
						<view v-if="maintenanceDetails.projectStatus == 6" class="tips5">项目状态&nbsp;|&nbsp;已解约</view>
						<view v-if="maintenanceDetails.projectStatus == 9" class="tips5">项目状态&nbsp;|&nbsp;已作废</view>
					</view>
					<view v-if="maintenanceDetails.projectStatus == 3" class="ff-margin-right-10 ff-font-12">
						<view v-if="maintenanceDetails.status == 0" class="tips2">维保状态&nbsp;|&nbsp;待维保</view>
						<view v-if="maintenanceDetails.status == 1" class="tips2">维保状态&nbsp;|&nbsp;维保中</view>
						<view v-if="maintenanceDetails.status == 2" class="tips2">维保状态&nbsp;|&nbsp;待审核</view>
						<view v-if="maintenanceDetails.status == 3" class="tips2">维保状态&nbsp;|&nbsp;待签发</view>
						<view v-if="maintenanceDetails.status == 5" class="tips2">维保状态&nbsp;|&nbsp;已完成</view>
						<view v-if="maintenanceDetails.status == 6" class="tips2">维保状态&nbsp;|&nbsp;已驳回</view>
						<view v-if="maintenanceDetails.status == 7" class="tips2">维保状态&nbsp;|&nbsp;待指派</view>
						<view v-if="maintenanceDetails.status == 8" class="tips2">维保状态&nbsp;|&nbsp;待提交</view>
						<view v-if="maintenanceDetails.status == 9" class="tips5">维保状态&nbsp;|&nbsp;已作废</view>
					</view>
					<view v-if="maintenanceDetails.rescissionStatus == 1"
						class="tips4 ff-color-fff ff-font-12 ff-margin-right-10">解约确认中</view>
					<view class="ff-flex-wrap">
						<view class="tips3 ff-font-12 ff-margin-right-10" v-if="maintenanceDetails.doneNumber > 0">
							已完成{{ maintenanceDetails.doneNumber }}次执业</view>
						<view class="tips3 ff-font-12" v-if="maintenanceDetails.mainNum">
							正在进行第{{ maintenanceDetails.mainNum }}次执业</view>
					</view>
				</view>
				<view class="ff-font-13 mechanismWorking-header-box-address ff-line-height-1-3 ff-flex">
					<view>建 筑 物 ：</view>
					<view>{{ maintenanceDetails.mainBuilding.buildingName }}</view>
				</view>
				<view class="ff-font-13 mechanismWorking-header-box-address ff-line-height-1-3 ff-flex">
					<view>社会单位：</view>
					<view>{{ maintenanceDetails.companyName }}</view>
				</view>
				<view class="ff-font-13 mechanismWorking-header-box-address ff-line-height-1-3 ff-flex">
					<view>项目地址：</view>
					<view>{{ maintenanceDetails.projectAddr }}</view>
				</view>
				<view
					class="mechanismWorking-header-box-butList ff-flex-between ff-font-13 ff-color-blue ff-margin-top-13">
					<view class="buts" @click.stop="projectDetailsClick">项目详情</view>
					<view class="buts" @click.stop="historyClick">历史记录</view>
					<view class="buts" @click.stop="deviceDetailsClick">设备详情</view>
				</view>
			</view>
			<view class="mechanismWorking-content ff-font-14 ff-padding-bottom-230">
				<view
					class="mechanismWorking-content-info-box ff-padding-12 ff-bg-fff ff-border-radius-10 ff-margin-top-12">
					<view
						class="mechanismWorking-content-info-box-title ff-font-16 ff-font-weight-600 ff-color-5C5F65 ff-border-radius-5">
						维保信息</view>
					<view class="mechanismWorking-content-info-box-content ff-line-height-1-3">
						<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
							<view class="mechanismWorking-content-info-box-content-left">指派人</view>
							<view class="mechanismWorking-content-info-box-content-right">
								{{ maintenanceDetails.firstAssignmentName }}&nbsp;{{ maintenanceDetails.firstAssignmentPhone }}
							</view>
							<zb-tooltip placement="left" ref="tooltip13" color="white">
								<view slot="content">
									<view>
										首次指派人：{{ maintenanceDetails.firstAssignmentName || '/' }}&nbsp;{{ maintenanceDetails.firstAssignmentPhone || '' }}
									</view>
									<view
										v-if="maintenanceDetails.firstAssignmentId != maintenanceDetails.assignmentId">
										最新指派人：{{ maintenanceDetails.assignName || '/' }}&nbsp;{{ maintenanceDetails.assignPhone || '' }}
									</view>
								</view>
								<u-icon size="28" name="info-circle-fill" color="#3178FF"></u-icon>
							</zb-tooltip>
						</view>
						<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
							<view class="mechanismWorking-content-info-box-content-left">指派时间</view>
							<view class="mechanismWorking-content-info-box-content-right ff-padding-left-4">
								{{ maintenanceDetails.firstAssignmentTime || '/' }}
							</view>
							<zb-tooltip placement="left" ref="tooltip13" color="white">
								<view slot="content">
									<view>首次指派时间：{{ maintenanceDetails.firstAssignmentTime || '/' }}</view>
									<view
										v-if="maintenanceDetails.firstAssignmentTime != maintenanceDetails.assignTime">
										最新指派时间：{{ maintenanceDetails.assignTime || '/' }}</view>
								</view>
								<u-icon size="28" name="info-circle-fill" color="#3178FF"></u-icon>
							</zb-tooltip>
						</view>
						<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
							<view class="mechanismWorking-content-info-box-content-left">维护保养周期</view>
							<view class="mechanismWorking-content-info-box-content-right"
								v-if="maintenanceDetails.maintenanceType == 1">月维保</view>
							<view class="mechanismWorking-content-info-box-content-right"
								v-if="maintenanceDetails.maintenanceType == 2">季维保</view>
							<view class="mechanismWorking-content-info-box-content-right"
								v-if="maintenanceDetails.maintenanceType == 3">半年维保</view>
							<view class="mechanismWorking-content-info-box-content-right"
								v-if="maintenanceDetails.maintenanceType == 4">年度维保</view>
							<view class="mechanismWorking-content-info-box-content-right"
								v-if="maintenanceDetails.maintenanceType == 5">特殊维保</view>
						</view>
						<view v-if="maintenanceDetails.signers">
							<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16"
								v-if="maintenanceDetails.signers.length > 0">
								<view class="mechanismWorking-content-info-box-content-left">技术负责人</view>
								<view class="mechanismWorking-content-info-box-content-right">
									<view v-for="(item, index) of maintenanceDetails.signers" :key="index">
										{{ item.username }}&nbsp;<text class="ff-color-blue ff-margin-left-3"
											@click.stop="telCllick(item.phone)">{{ item.phone }}</text>
									</view>
								</view>
							</view>
						</view>
						<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
							<view class="mechanismWorking-content-info-box-content-left">项目负责人</view>
							<view class="mechanismWorking-content-info-box-content-right">
								<view v-for="(item, index) of maintenanceDetails.leaders" :key="index">
									{{ item.username }}&nbsp;<text class="ff-color-blue ff-margin-left-3"
										@click.stop="telCllick(item.phone)">{{ item.phone }}</text>
								</view>
							</view>
						</view>
						<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
							<view class="mechanismWorking-content-info-box-content-left">执业人员</view>
							<view class="mechanismWorking-content-info-box-content-right">
								<view class="ff-line-height-1-5" v-for="(item, index) of maintenanceDetails.operators"
									:key="index">
									{{ item.username }}&nbsp;<text class="ff-color-blue ff-margin-left-3"
										@click.stop="telCllick(item.phone)">{{ item.phone }}</text>
								</view>
							</view>
						</view>
						<view class="ff-flex ff-padding-left-5 ff-margin-bottom-16">
							<view class="mechanismWorking-content-info-box-content-left">开始维保时间</view>
							<view class="mechanismWorking-content-info-box-content-right">
								{{ maintenanceDetails.startTime || '/' }}
							</view>
						</view>
						<view class="ff-flex ff-padding-left-5">
							<view class="mechanismWorking-content-info-box-content-left">结束维保时间</view>
							<view class="mechanismWorking-content-info-box-content-right">
								{{ maintenanceDetails.endTime || '/' }}
							</view>
						</view>
					</view>
				</view>
				<view>
					<view
						class="mechanismWorking-content-info-box ff-padding-12 ff-bg-fff ff-border-radius-10 ff-margin-top-12">
						<view class="ff-flex-between ff-relative">
							<view
								class="mechanismWorking-content-info-box-title ff-font-16 ff-font-weight-600 ff-color-5C5F65 ff-border-radius-5">
								现场维保情况</view>
							<view v-if="facilitiesListOther">
								<view class="mechanismWorking-content-add" @click="addFacilitiesClick"
									v-if="facilitiesListOther.length > 0 && practiceState">新增</view>
							</view>
						</view>
						<view class="mechanismWorking-content-info-box-content">
							<view v-if="maintenanceDetails.mainBuilding.mainBuildingFacilities">
								<view
									class="ff-padding-left-5 mechanismWorking-content-info-box-content-fireList ff-padding-top-15 ff-padding-bottom-15 ff-align-items-one ff-flex-between"
									v-for="(item, ind) of maintenanceDetails.mainBuilding.mainBuildingFacilities"
									:key="ind" @click="fireFacilitiesClick(item, ind)">
									<view>{{ ind + 1 }}.&nbsp;{{ item.facilitiesTypeName }}</view>
									<view class="ff-align-items-one">
										<view class="ff-color-red ff-margin-right-15"
											v-if="item.isExtra == 1 && practiceState"
											@click.stop="deleteOtherFacilities(item)">删除</view>
										<u-icon name="arrow-right" color="#3178FF" size="32"></u-icon>
									</view>
								</view>
								<view class="ff-color-999"
									v-if="!maintenanceDetails.mainBuilding.mainBuildingFacilities">
									未维护消防设施设备数量
								</view>
							</view>
						</view>
					</view>
					<!-- 消防设施选择 -->
					<u-select v-model="facilitiesOtherState" mode="single-column" :list="facilitiesListOther"
						:safe-area-inset-bottom="true" label-name="facilitiesTypeName" value-name="facilitiesTypeId"
						title="新增消防设施" @confirm="facilitiesOtherConfirm"></u-select>
				</view>
				<view
					class="mechanismWorking-content-info-box ff-padding-12 ff-bg-fff ff-border-radius-10 ff-margin-top-12">
					<view
						class="mechanismWorking-content-info-box-title ff-font-16 ff-font-weight-600 ff-color-5C5F65 ff-border-radius-5">
						附件：测试打印条</view>
					<view>
						<view v-if="practiceState">
							<u-row gutter="20">
								<u-col span="3" v-for="(item, index) of maintenanceDetails.testAttachList" :key="index">
									<view class="ff-margin-bottom-10 ff-relative" @click="previewClick(item)">
										<image class="mechanismWorking-content-info-box-content-img"
											:src="item.attachUrl" mode="" />
										<view v-if="item.creater == userInfo.id" @click.stop="deteleImgClick(index)"
											class="closeIcon"><u-icon name="close" color="#fff" size="22"></u-icon>
										</view>
									</view>
								</u-col>
								<u-col span="3">
									<image class="mechanismWorking-content-info-box-content-img"
										@click="upateImgClick()"
										src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/upate-icon.png"
										mode="" />
								</u-col>
							</u-row>
						</view>
						<view v-else>
							<view>
								<view>
									<u-row gutter="20">
										<u-col span="3" v-for="(item, index) of maintenanceDetails.testAttachs"
											:key="index">
											<view class="ff-margin-bottom-10" @click="previewClick(item)">
												<image class="mechanismWorking-content-info-box-content-img" :src="item"
													mode="" />
											</view>
										</u-col>
									</u-row>
								</view>
								<view v-if="!maintenanceDetails.testAttachs"
									class="ff-color-999 ff-padding-left-5 ff-padding-bottom-30">暂无附件</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mechanismWorking-operation">
			<view class="ff-padding-10 ff-flex-between">
				<view>
					<view v-if="maintenanceDetails.canEnd == 1"
						class="ff-color-3D4060 ff-font-weight-600 ff-font-15 mechanismWorking-operation-endBut"
						@click.stop="endMaintenanceOne">结束执业</view>
				</view>
				<view class="ff-align-items-one">
					<view class="mechanismWorking-operation-location ff-margin-right-18" @click.stop="refreshClick">
						<image src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/refresh.png"
							mode="">
						</image>
					</view>
					<view class="mechanismWorking-operation-location" @click.stop="punchPositionClick">
						<image src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/location.png"
							mode="">
						</image>
					</view>
				</view>
			</view>
			<view class="ff-bg-e9effd">
				<view class="mechanismWorking-operation-info ff-align-items-one ff-flex-between ff-font-13">
					<view class="ff-align-items-one" v-if="practiceInfo.workingNum">
						<image
							src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/maintenance-people.png"
							mode=""></image>
						<view><text class="ff-color-blue ff-font-weight-600">{{ practiceInfo.workingNum }}</text>人正在执业
						</view>
					</view>
					<view class="ff-line-height-1-3 ff-text-right finishTime">预计完成时间: {{ practiceInfo.endTime }}</view>
				</view>
				<view class="mechanismWorking-operation-card ff-margin-10 ff-flex-between ff-align-items-one">
					<view class="ff-font-12">
						<view class="ff-align-items-one ff-margin-bottom-8">
							<view>所需工时：</view>
							<view>
								<text class="ff-color-fff ff-margin-right-5">{{ practiceInfo.needTimeFmt }}</text>
							</view>
						</view>
						<view @click.stop="tipsClick1" class="ff-align-items-one ff-margin-bottom-8">
							<view>完成工时：</view>
							<view>
								<text class="ff-color-fff ff-margin-right-5">{{ practiceInfo.passTimeFmt }}</text>
								<u-icon v-if="tipsList.length > 0" size="32" name="info-circle-fill"
									color="#3178FF"></u-icon>
							</view>
						</view>
						<view class="ff-align-items-one">
							<view>剩余工时：</view>
							<view>
								<text class="ff-color-fff ff-margin-right-5">{{ practiceInfo.remainingTimeFmt }}</text>
							</view>
						</view>
					</view>
					<view class="ff-relative">
						<view class="maskBox" v-show="maskBoxState"></view>
						<view v-if="!practiceState" class="ff-align-items-one mechanismWorking-operation-card-start"
							@click.stop="practiceClick(1)">
							<u-icon name="play-right-fill" color="#fff" size="30"></u-icon>
							<view class="ff-margin-left-5 ff-font-14 ff-color-fff">开始执业</view>
						</view>
						<view v-else class="ff-align-items-one mechanismWorking-operation-card-suspend"
							@click.stop="practiceClick(2)">
							<u-icon name="pause" color="#fff" size="30"></u-icon>
							<view class="ff-font-14 ff-margin-left-5 ff-color-fff">暂停执业</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 组件区 -->
		<u-toast ref="uToast" />
		<f-loading ref="loading" />
		<u-modal v-model="locationModal" title="温馨提示" :content-style="{ 'line-height': '1.5' }"
			content="获取小程序openid失败！" />
		<u-modal v-model="deleteImgModal" @confirm="deleteImgConfirm" :show-cancel-button="true" title="温馨提示"
			:content-style="{ 'line-height': '1.5' }" content="您确定要删除这张照片吗？" />
		<u-modal v-model="deleteFacilitiesModal" @confirm="deleteFacilitiesConfirm" :show-cancel-button="true"
			title="温馨提示" :content-style="{ 'line-height': '1.5' }" :content="deleteFacilitiesContent" />
		<u-modal v-model="tipsModal" title="温馨提示" :content-style="{ 'line-height': 1.5 }" :content="tipsContent" />
		<view class="loaderMask" v-show="loadControl" @click.stop="" @touchmove.stop="">
			<view class="loader">
				<div class="circleBox"></div>
				<image class="boxCircleImg"
					src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/logo.png"></image>
				<view class="ff-color-fff ff-font-14 loadingTxt ff-text-center">{{ loadingTxt }}</view>
			</view>
		</view>
		<u-modal v-model="tipsState" title="作废记录">
			<view class="slot-content">
				<view class="ff-padding-15 ff-line-height-1-3 ff-font-15">
					<view class="ff-margin-bottom-5" v-for="(item, index) of tipsList" :key="index">
						{{`${tipsList.length > 9 ? '':'0'}${index+1}.`}}
						{{`${item.cancelDepartmentName}在${item.cancelTime}发起作废。被作废操作员:${item.username}；被作废有效工时：${item.timeDurationTranslated}`}}
					</view>
				</view>
			</view>
		</u-modal>
		<u-modal v-model="tips1State" title="工时作废警告" @confirm="confirmTips">
			<view class="slot-content">
				<view class="ff-padding-15 ff-line-height-1-3 ff-font-15">
					{{tips1List}}
				</view>
			</view>
		</u-modal>
		<!-- 自定义弹窗 -->
		<f-showModel @setVisible="setVisible" :customShowModal.sync="customShowModal" />
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import config from '@/tools/config.js';
	import {
		getPermission
	} from '@/tools/utils.js'
	export default {
		name: 'mechanismWorking',
		components: {},
		data() {
			return {
				tipsId: '', // 工时警告id
				tips1List: {}, // 工时作废提示
				tips1State: false, // 工时作废警告弹窗显/隐
				tipsList: [], // 作废提示集合
				tipsState: false, // 工时作废弹窗显/隐
				faceTestState: false,
				tipsModal: false, // 提示弹窗显/隐
				tipsContent: '', // 提示弹窗具体内容
				facilitiesOtherState: false, // 消防设施列表弹窗显/隐
				deleteFacilitiesModal: false, // 删除消防设施弹窗显/隐
				deleteFacilitiesContent: '', // 删除消防设施弹窗内容
				deleteFacilitiesItem: {}, // 删除消防设施弹窗当前选中的内容
				locationModal: false, // 定位失败弹框显/隐
				deleteImgModal: false, // 删除照片弹框显/隐
				deleteImgIndex: '', // 当前删除图片的index
				openid: '', // openid
				maintenanceId: '', // 维保id
				maintenanceDetails: {}, // 维保详情（所有的数据，包括消防设施和图片）
				maintenanceAttachs: [], // 需提交的附件(照片)
				practiceState: false, // 是否开启执业, 当前执业状态: 1.进行中  2.已暂停  3.作废
				practiceInfo: {}, // 执业人和时间的信息
				facilitiesListOther: [], // 剩余的消防设施
				// 人脸识别相关
				faceBox: false, // 刷脸弹窗
				faceInfo: {
					faceState: '', // 维保状态（1开始，2暂停，3结束）
					latitude: '', // 纬度
					longitude: '', // 经度
					accessToken: '', // 百度accesstoken
					sessionCode: '', // 用户需要大声读出数字
					videoPath: '', // 上传视频后返回的临时视频路径
					videoBase64: '', // 视频base64
					imageBase64: '' // 图片base64
				},
				maintenanceParams: {}, // 开始or暂停维保请求的参数
				loadControl: false, // laoding显示隐藏
				loadingTxt: '', // loading的文字描述
				maskBoxState: false, // 按钮遮盖
				// 自定义弹窗内容
				customShowModal: {
					visible: false, // 显隐
					title: '', // 标题,
					content: '', // 内容,
					cancelText: '', // 取消按钮文案,
					confirmText: '', // 确定按钮文案
					messageType: '', // 到期or未到期
					operatorFlag: null, // 单证/双证
				}
			};
		},
		onLoad(e) {
			// console.log('前页面传过来的数据------', e);
			uni.getNetworkType({ // 获取网络类型。
				complete: res => {
					let networkType = res.networkType || 'none';
					if (networkType != 'none') {
						this.maintenanceId = e.maintenanceId;
						this.refreshClick() // 获取数据
						this.getOpenid(); // 获取openid
					}
				}
			})
		},
		// 离开当前页面
		onUnload() {
			this.removeAllMaintenanceFacilities(); // 清空消防设施缓存的数据
		},
		async onShow() {
			// 判断当前网络情况
			let that = this
			uni.getNetworkType({
				complete: res => {
					let networkType = res.networkType || 'none';
					if (networkType != 'none') {
						that.refreshClick(); // 监听当前的页面请求的接口数据
						uni.getSetting({
							success(res) {
								if (!res.authSetting['scope.camera']) {
									that.getPermission() // 判断获取相机的权限
								}
							}
						})
					}
				}
			});
		},
		computed: {
			...mapState({
				configInfo: modules => modules.infoList.configInfo,
				userInfo: modules => modules.infoList.userInfo
			})
		},
		methods: {
			...mapMutations(['setAllMaintenanceFacilities', 'removeAllMaintenanceFacilities', 'changeTabberIndex']),
			// 作废提示1
			async tipsClick() {
				const data = await this.$http.post({
					url: `/serviceOrg/queryMaintenanceCancelLog/${this.maintenanceId}`
				})
				this.tipsList = data.data
			},
			// 作废提示2
			async tipsClick1() {
				this.$refs.loading.openLoading('获取中···');
				const data = await this.$http.post({
					url: `/serviceOrg/queryMaintenanceCancelLog/${this.maintenanceId}`
				})
				this.$refs.loading.closeLoading();
				this.tipsList = data.data
				this.tipsState = true
			},
			// 判断是否有未读作废提醒
			async getQueryUserNotReadLog() {
				const data = await this.$http.post({
					url: '/serviceOrg/queryUserNotReadLog'
				});
				// console.log('判断是否有未读作废提醒-----', data);
				if (data.code == 200 && data.data.cancelDepartmentName) {
					let dat = data.data
					this.tips1State = true
					this.tips1List =
						`${dat.cancelDepartmentName}在${dat.cancelTime}作废了项目【${dat.projectName}】的有效工时，请重新开始执业。如有异议，请联系对应的救援机构。`
					this.tipsId = dat.id
				}
			},
			// 确定并阅读了工时作废警告
			async confirmTips() {
				const data = await this.$http.post({
					url: `/serviceOrg/userReadLog/${this.tipsId}`
				})
				// console.log('确定并阅读了工时作废警告', data)
				if (data.code == 200) {
					this.refreshClick() // 刷新页面
				} else {
					this.$refs.uToast.show({
						title: data.msg,
						type: 'error'
					});
				}
			},
			// 返回首页
			goBack() {
				this.$pageJump.reLaunch('/pages/maintenance/mechanism/Maintenance');
			},
			// 获取摄像头授权
			getPermission() {
				getPermission({
					permission: 'camera',
					permissionName: '摄像头',
					success: () => {},
					cancel: () => {
						uni.showModal({
							title: '温馨提示',
							content: '相机权限获取失败，请到设置中打开相机权限',
							showCancel: false, // 不展示取消按钮
							confirmColor: '#3178FF',
							confirmText: '确定',
							success: () => {
								uni.openAppAuthorizeSetting() // 打开系统设置页面
							}
						})
					}
				})
			},
			//-----------------------------数据加载区----------------------------
			// 计算时间差
			diffTime(start) {
				let staytimeGap = new Date().getTime() - new Date(start).getTime();
				let stayMin = Math.floor(staytimeGap / (60 * 1000)); // 分钟
				return stayMin
			},
			// 判断是否需要抽查
			async getSpotCheck() {
				let that = this
				const data = await this.$http.post({
					url: '/serviceOrg/checkTask/userPage',
					data: {
						current: 1,
						size: 1,
						checkStatus: 1
					}
				});
				// console.log('有待抽查任务需要处理,请立即处理-----', data);
				if (data.code == 200 && data.data.records.length > 0) {
					let receiveTime = data.data.records[0].receiveTime // 系统开始抽查时间
					if (this.diffTime(receiveTime) < 15) {
						uni.showModal({
							title: '温馨提示',
							content: '当前有待抽查任务需要处理, 请立即处理！',
							confirmColor: '#3178FF',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									that.$pageJump.reLaunch(
										'/pages/maintenance/public/personal/spotTask/spotTask'
									);
								}
							},
						})
					}
				}
			},
			// 获取维保详情（所有的数据，包括消防设施和图片）
			async getMaintenanceDetails() {
				this.$refs.loading.openLoading('加载中···');
				const data = await this.$http.post({
					url: `/maintenance/detailV3/${this.maintenanceId}`
				});
				this.$refs.loading.closeLoading();
				// console.log('获取维保详情（所有的数据，包括消防设施和图片）------', data);
				if (data.code == 200) {
					this.maintenanceDetails = data.data;
					if (this.maintenanceDetails.testAttachList) {
						this.maintenanceAttachs = []
						this.maintenanceDetails.testAttachList.filter(item => {
							this.maintenanceAttachs.push(item.attachUrl) // 给维保附件照片赋值
						})
					}
					this.getOpenPractice(); // 是否开始执业
					this.getDevicePicsTipsList() // 获取各个设备的照片提示语集合
				}
			},
			// 获取消防设施设备字典列表
			async getDevicePicsTipsList() {
				const data = await this.$http.post({
					url: '/maintenance/getTempleteFacilitiesItemList',
					data: {
						facilitiesTypeId: ''
					}
				})
				// console.log('获取消防设施设备字典列表-----', data)
				if (data.code == 200) {
					const tipsList = data.data
					const mainBuildingFacilitiesList = this.maintenanceDetails.mainBuilding.mainBuildingFacilities
					mainBuildingFacilitiesList.forEach((res, index) => {
						this.$set(res, 'tipsList', [])
						tipsList.forEach(item => {
							if (item.facilitiesTypeId == res.facilitiesTypeId && item
								.isMustTakePictures) {
								mainBuildingFacilitiesList[index].tipsList.push(item)
							}
						})
					})
					this.setAllMaintenanceFacilities(mainBuildingFacilitiesList); // 把数据储存到vuex
					uni.setStorageSync('allMaintenanceFacilities', mainBuildingFacilitiesList); // 把数据储存到本地
				}
			},
			// 获取执业人和时间的信息
			async getPracticeInfo() {
				try {
					const data = await this.$http.get({
						url: `/maintenance/getNeedTimeToEnd/${this.maintenanceId}`
					});
					this.$refs.loading.closeLoading();
					// console.log('获取执业人和时间的信息------', data);
					if (data.code == 200) {
						this.practiceInfo = data.data;
					}
				} catch {}
			},
			// 获取openid
			getOpenid() {
				let that = this;
				uni.login({
					provider: 'weixin',
					success: res => {
						// console.log('登录成功：', res);
						// 获取临时登录凭证code
						that.$http
							.get({
								url: '/getOpenId',
								data: {
									code: res.code
								}
							})
							.then(item => {
								// console.log('小程序openid------:', item);
								that.openid = item.data;
							});
					},
					fail: () => {
						// console.log('登录失败，获取小程序openid失败------：', err);
						this.locationModal = true;
					}
				});
			},
			// 获取是否开启执业
			async getOpenPractice() {
				try {
					this.$refs.loading.openLoading('加载中···');
					let params = {
						maintenanceId: this.maintenanceId
					}; // 维保记录ID
					const data = await this.$http.post({
						url: `/maintenance/getCurrentPractice`,
						data: params
					});
					this.$refs.loading.closeLoading();
					// console.log('获取是否开启执业------', data);
					if (data.code == 200 && data.data) {
						let info = data.data;
						// 当前执业状态: 1.进行中  2.已暂停  3.作废
						if (info.status == 1) {
							this.practiceState = true;
						} else if (info.status == 2 || info.status == 3) {
							this.practiceState = false;
						}
					}
				} catch {
					this.$refs.loading.closeLoading();
				}
			},
			// -------------跳转系列-----------------------
			// 点击进入项目详情
			projectDetailsClick() {
				this.$pageJump.navigateTo('/pages/maintenance/public/demand/demandDetails?id=' + this
					.maintenanceDetails.projectId);
			},
			// 点击进入历史记录
			historyClick() {
				this.$pageJump.navigateTo(
					'/pages/maintenance/mechanism/home/components/details/projectMaintenanceRecord?id=' +
					this
					.maintenanceDetails.projectId);
			},
			// 点击进入设备详情
			deviceDetailsClick() {
				this.$pageJump.navigateTo(
					'/pages/maintenance/mechanism/home/components/mechanismWork/components/deviceDetails?id=' +
					this
					.maintenanceId);
			},
			// 点击跳转到现场维保情况
			fireFacilitiesClick(item, index) {
				let paramsInfo = {
					id: this.maintenanceId,
					index: index,
					practiceState: this.practiceState,
					// maintenanceId: this.maintenanceDetails.id,
					maintenanceBuildingId: this.maintenanceDetails.mainBuilding.id,
					fireFacilitiesId: item.id,
					facilitiesTypeId: item.facilitiesTypeId
				};
				this.$pageJump.navigateTo(
					'/pages/maintenance/mechanism/home/components/mechanismWork/components/fireFacilities?paramsInfo=' +
					JSON.stringify(paramsInfo));
			},
			// 点击刷新页面
			refreshClick() {
				let that = this
				uni.getNetworkType({
					complete: res => {
						let networkType = res.networkType || 'none';
						if (networkType == 'none') {
							uni.showModal({
								title: '温馨提示',
								content: '网络请求超时，请稍后再试！',
								confirmColor: '#3178FF',
								showCancel: false, // 是否显示取消按钮
								success: function(res) {
									if (res.confirm) {}
								}
							})
							return
						} else {
							that.maskBoxState = false
							that.getQueryUserNotReadLog() // 作废未读提示
							that.getSpotCheck() // 抽查任务
							that.getMaintenanceDetails(); // 获取维保详情（所有的数据，包括消防设施和图片）
							that.getPracticeInfo(); // 获取执业人和时间的信息
							that.getFacilitiesListOther(); // 获取剩余维保设施数据列表
							// that.getOpenid(); //  获取openid
							this.tipsClick() // 获取作废记录
						}
					}
				});
			},
			// 点击进入打卡位置页面
			punchPositionClick() {
				let that = this;
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					success: function(res) {
						// console.log('当前坐标点------', res);
						let coordinate = {
							nowLatitude: res.latitude,
							nowLongitude: res.longitude,
							projectName: that.maintenanceDetails.projectName,
							projectLatitude: that.maintenanceDetails.latitude,
							projectLongitude: that.maintenanceDetails.longitude,
							faceRecognitionRange: that.configInfo.faceRecognitionRange / 2
						};
						that.$pageJump.navigateTo(
							'/pages/maintenance/mechanism/home/components/mechanismWork/components/punchPosition?coordinate=' +
							JSON.stringify(coordinate));
					},
					fail() {
						that.tipsContent = '当前位置获取失败，请您开启GPS定位权限后再试！';
						that.tipsModal = true;
					}
				});
			},
			// 拨打电话
			telCllick(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			//------------------------业务区------------------------------------------
			// 上传维保附件系列操作 --------------------------------------------------
			// 上传维保附件-----照片
			upateImgClick() {
				let that = this
				uni.getNetworkType({
					complete: res => {
						let networkType = res.networkType || 'none';
						if (networkType == 'none') {
							uni.showModal({
								title: '温馨提示',
								content: '网络请求超时，请稍后再试！',
								confirmColor: '#3178FF',
								showCancel: false, // 是否显示取消按钮
								success: function(res) {
									if (res.confirm) {}
								}
							})
							return
						} else {
							const {
								cameraAuthorized,
								microphoneAuthorized,
								osName
							} = uni.getSystemInfoSync()

							if (!cameraAuthorized) {
								uni.showModal({
									title: '提示',
									content: '您关闭了摄像头权限，请允许微信使用摄像头权限',
									confirmText: '去设置',
									success: (res) => {
										if (res.confirm) {
											uni.openAppAuthorizeSetting()
										}
									}
								})
								return
							}
							// ios 摄像头&麦克风绑定
							if (!microphoneAuthorized && osName === 'ios') {
								uni.showModal({
									title: '提示',
									content: '您关闭了麦克风权限，请允许微信使用麦克风权限',
									confirmText: '去设置',
									success: (res) => {
										if (res.confirm) {
											uni.openAppAuthorizeSetting()
										}
									}
								})
								return
							}
							let params = {
								maintenanceId: that.maintenanceId,
								maintenanceBuildingId: that.maintenanceDetails.mainBuilding
									.id,
								attachs: that.maintenanceDetails.testAttachList || []
							}
							that.$pageJump.navigateTo(
								`/pages/maintenance/mechanism/home/components/mechanismWork/components/cameraUnit?params=${JSON.stringify(params)}`
							)
						}
					}
				})
			},
			// 预览维保附件----照片
			previewClick(item) {
				uni.previewImage({
					urls: this.maintenanceAttachs,
					current: item.attachUrl
				});
			},
			// 删除维保附件（照片)----打开弹窗
			deteleImgClick(index) {
				this.deleteImgIndex = index;
				this.deleteImgModal = true;
			},
			// 删除维保附件(照片)----确认操作
			deleteImgConfirm() {
				let that = this
				this.maintenanceAttachs.splice(this.deleteImgIndex, 1);
				this.maintenanceDetails.testAttachList.splice(this.deleteImgIndex, 1)
				this.$refs.loading.openLoading('删除中···');
				let params = {
					maintenanceId: this.maintenanceId,
					maintenanceBuildingId: this.maintenanceDetails.mainBuilding.id,
					attachList: this.maintenanceDetails.testAttachList
				};
				this.$http
					.post({
						url: '/maintenance/updTestAttach',
						data: params
					})
					.then(res => {
						// console.log('更新照片给后台');;
						this.$refs.loading.closeLoading();
						if (res.code == 200) {
							this.$refs.uToast.show({
								title: '删除成功',
								type: 'success'
							});
							this.getMaintenanceDetailsOther() // 重新获取详情数据
						} else {
							uni.showModal({
								title: '无法删除',
								content: res.msg,
								confirmText: '我知道了',
								confirmColor: '#3178FF',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {
										that.getMaintenanceDetailsOther() // 重新获取详情数据
									}
								},
							})
						}
					});
			},
			// 获取维保详情（所有的数据，包括消防设施和图片）
			async getMaintenanceDetailsOther() {
				const data = await this.$http.post({
					url: `/maintenance/detailV3/${this.maintenanceId}`
				});
				// console.log('获取维保详情（所有的数据，包括消防设施和图片）------', data);
				if (data.code == 200) {
					this.maintenanceDetails = data.data;
					if (this.maintenanceDetails.testAttachList) {
						this.maintenanceAttachs = []
						this.maintenanceDetails.testAttachList.filter(item => {
							this.maintenanceAttachs.push(item.attachUrl) // 给维保附件照片赋值
						})
					}
				}
			},
			// -----------------新增消防维保类型----------------------
			// 获取消防剩余维保类型
			async getFacilitiesListOther() {
				const data = await this.$http.get({
					url: `/maintenance/listOtherTypes/${this.maintenanceId}`
				});
				// console.log('获取剩余维保设施数据列表------', data);
				if (data.code == 200) {
					this.facilitiesListOther = data.data;
				}
			},
			// 打开新增消防设施弹窗
			addFacilitiesClick() {
				this.facilitiesOtherState = true;
			},
			// 新增消防设施---确定操作
			facilitiesOtherConfirm(e) {
				this.$refs.loading.openLoading('新增中···');
				let params = {
					maintenanceId: this.maintenanceId,
					facilitiesTypeId: e[0].value
				};
				this.$http
					.post({
						url: '/maintenance/addOtherType',
						data: params
					})
					.then(res => {
						// console.log('新增消防设施---返回结果', res);
						this.$refs.loading.closeLoading();
						if (res.code == 200) {
							this.getMaintenanceDetails(); // 获取维保详情（所有的数据，包括消防设施和图片）
							this.getFacilitiesListOther(); // 获取剩余维保设施数据列表
							this.$refs.uToast.show({
								title: '新增成功',
								type: 'success'
							});
						} else {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							});
						}
					});
			},
			// 新增消防设施---打开删除弹窗操作
			deleteOtherFacilities(item) {
				this.deleteFacilitiesItem = item;
				this.deleteFacilitiesContent = `您确定删除“${item.facilitiesTypeName}”吗？`;
				this.deleteFacilitiesModal = true;
			},
			// 新增消防设施---确定删除造作
			deleteFacilitiesConfirm() {
				this.$refs.loading.openLoading('删除中···');
				let params = {
					maintenanceId: this.maintenanceId,
					facilitiesTypeId: this.deleteFacilitiesItem.facilitiesTypeId
				};
				this.$http
					.post({
						url: '/maintenance/removeOtherType',
						data: params
					})
					.then(res => {
						// console.log('删除消防设施---返回结果', res);
						this.$refs.loading.closeLoading();
						if (res.code == 200) {
							this.getMaintenanceDetails(); // 获取维保详情（所有的数据，包括消防设施和图片）
							this.getFacilitiesListOther(); // 获取剩余维保设施数据列表
							this.$refs.uToast.show({
								title: '删除成功',
								type: 'success'
							});
						} else {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							});
						}
					});
			},
			// ---------------------------------刷脸系列操作--------------------------------------------业务
			// 开启执业or暂停执业-------第一步 定位
			practiceClick(type) {
				let that = this;
				// console.log('当前环境：', uni.getSystemInfoSync().platform)
				uni.getNetworkType({
					complete: res => {
						let networkType = res.networkType || 'none';
						if (networkType == 'none') {
							that.maskBoxState = false
							that.tipsContent = '网络请求超时，请稍后再试！';
							that.tipsModal = true;
						} else {
							that.checkCertificateValid(type) // 检测用户证书是否到期
						}
					},
					fail() {
						that.maskBoxState = false
						that.tipsContent = '网络请求超时，请稍后再试！';
						that.tipsModal = true;
					}
				});

			},
			// 检查证书是否到期
			async checkCertificateValid(type) {
				let that = this
				const data = await this.$http.post({
					url: '/maintenance/checkForCertificate?maintenanceId=' + this.maintenanceId,

				})
				// console.log('检查证书是否到期', data)
				if (data.code == 200) {
					if (data.data.certificateInValid && data.data.leader) {
						this.customShowModal.visible = true // 显隐
						this.customShowModal.title = '证书已到期' // 标题
						this.customShowModal.content = data.data.msg
					} else {
						that.checkLocation(type) // 检测当前用户的地理位置
					}
				} else {
					uni.showModal({
						title: '温馨提示',
						content: data.msg,
						confirmColor: '#3178FF',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								// console.log('用户点击确定')
							}
						},
					})
				}
			},
			// 关闭弹窗
			setVisible() {
				this.customShowModal.visible = false // 显隐
			},
			// 检测当前用户的地理位置
			checkLocation(type) {
				let that = this;
				//  || uni.getSystemInfoSync().platform == 'devtools'
				if (uni.getSystemInfoSync().platform == 'windows' || uni.getSystemInfoSync()
					.platform == 'mac' || uni
					.getSystemInfoSync().platform == 'linux') {
					uni.showModal({
						title: '警告',
						content: '检测到您正在使用电脑登录维保系统，请使用手机登录！',
						showCancel: false, // 是否显示取消按钮，默认为 true
						confirmColor: '#3178FF',
						success: res => {
							if (res.confirm) {}
						}
					});
					return
				}
				that.maskBoxState = true
				let setDistance = this.configInfo.faceRecognitionRange || config
					.location_distance; // 后台限制刷脸的范围
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					success: function(res) {
						that.faceInfo.latitude = res.latitude;
						that.faceInfo.longitude = res.longitude;
						let distance = that.$check.getDistance(that.maintenanceDetails
							.latitude, that
							.maintenanceDetails.longitude, res.latitude, res
							.longitude);
						if (parseFloat(distance) * 1000 <= setDistance) {
							// 开启执业
							if (type == 1) {
								that.faceInfo.faceState = 1; // 开始维保
								that.checkFaceClick(1) // 刷脸前的校验----开始维保
								return;
							}
							// 暂停执业
							if (type == 2) {
								if (that.userInfo.id == that.maintenanceDetails
									.leaders[0]
									.userId) {
									uni.showModal({
										title: '是否暂停执业？',
										content: '项目负责人暂停执业后，本项目的有效工时也暂停计算。',
										confirmColor: '#3178FF',
										cancelColor: '#606266',
										success: res => {
											if (res.confirm) {
												that.faceInfo.faceState =
													2; // 暂停维保
												that.checkFaceClick(
													2
												) // 刷脸前的校验----暂停维保
											} else {
												that.maskBoxState = false
											}
										}
									});
								} else {
									that.faceInfo.faceState = 2; // 暂停维保
									that.checkFaceClick(2) // 刷脸前的校验----暂停维保
								}
								return;
							}
						} else {
							that.maskBoxState = false
							that.tipsContent =
								`您距离项目所在地中心点超过${setDistance}米, 请先到维保地点后再定位！`;
							that.tipsModal = true;
						}
					},
					fail() {
						that.maskBoxState = false
						that.tipsContent = '当前位置获取失败，请您开启GPS定位权限后再试！';
						that.tipsModal = true;
					}
				});
			},
			// 刷脸前的校验
			async checkFaceClick(type) {
				let that = this
				this.$refs.loading.openLoading('校验中···');
				const data = await this.$http.post({
					url: `/maintenance/checkForPractice`,
					data: {
						maintenanceId: this.maintenanceId,
						openid: this.openid,
						type: type // 1开始执业 2暂停执业 3结束执业
					}
				});
				// console.log('刷脸前的校验------', data);
				if (data.code == 200) {
					if (data.data.status == 0) {
						if (type == 3) {
							uni.showModal({
								title: '是否结束现场执业？',
								content: '现场执业结束后，不允许再编辑现场维保情况。请确认现场维保情况是否都已经填写。',
								confirmColor: '#3178FF',
								cancelColor: '#606266',
								success: res => {
									if (res.confirm) {
										that.faceCertificationOne(); // 开启刷脸
									} else {
										that.refreshClick(); // 重新刷新页面
									}
								}
							});
						} else {
							that.faceCertificationOne(); // 开启刷脸
						}
					} else if (data.data.status == 1) {
						uni.showModal({
							title: '温馨提示',
							content: data.data.msg,
							confirmColor: '#3178FF',
							showCancel: true,
							success: function(res) {
								if (res.confirm) {
									setTimeout(() => {
										if (type == 3) {
											uni.showModal({
												title: '是否结束现场执业？',
												content: '现场执业结束后，不允许再编辑现场维保情况。请确认现场维保情况是否都已经填写。',
												confirmColor: '#3178FF',
												cancelColor: '#606266',
												success: res => {
													if (res
														.confirm
													) {
														that
															.faceCertificationOne(); // 开启刷脸
													} else {
														that
															.refreshClick(); // 重新刷新页面
													}
												}
											});
										} else {
											that
												.faceCertificationOne(); // 开启刷脸
										}
									}, 500)
								} else {
									that.refreshClick(); // 重新刷新页面
								}
							},
						})
					} else if (data.data.status == 2) {
						uni.showModal({
							title: '温馨提示',
							content: data.data.msg,
							confirmText: '确认',
							confirmColor: '#3178FF',
							showCancel: false,
							success: res => {
								if (res.confirm) {
									that.refreshClick(); // 重新刷新页面
								}
							}
						});
					} else if (data.data.status == 3) {
						uni.showModal({
							title: '无法结束执业',
							content: data.data.msg,
							confirmText: '好的',
							confirmColor: '#3178FF',
							showCancel: false,
							success: res => {
								if (res.confirm) {
									that.refreshClick(); // 重新刷新页面
								}
							}
						});
					}
				} else {
					this.maskBoxState = false
					this.tipsContent = data.msg;
					this.tipsModal = true;
					this.refreshClick() // 刷新数据
				}
				this.$refs.loading.closeLoading();
			},
			// 开启刷脸---第一步（录视频）
			faceCertificationOne() {
				let that = this;
				// that.$refs.loading.openLoading(''); // 打开loading动画
				that.loadControl = true; // 打开loading动画
				uni.showModal({
					title: '录制活体人脸视频警告',
					content: '为了保障人脸识别的准确性，在视频录制过程中，请将面部正对手机摄像头，并大声读出：消防技术服务。',
					confirmText: '开始认证',
					confirmColor: '#3178FF',
					cancelColor: '#606266',
					success: function(res) {
						if (res.confirm) {
							// that.$refs.loading.openLoading('视频解析中1···'); // 打开loading动画
							that.loadingTxt = '视频解析中···';
							uni.chooseVideo({
								count: 1,
								compressed: true,
								sourceType: ['camera'],
								camera: 'front',
								maxDuration: 5,
								success(res) {
									// console.log('压缩前的视频', res);
									that.faceInfo.videoPath = res
										.tempFilePath;
									uni.getFileSystemManager().readFile({
										filePath: that.faceInfo
											.videoPath,
										encoding: 'base64', //编码格式
										success: res => {
											that.faceInfo
												.videoBase64 =
												res.data;
											let videoData = {
												video: that.faceInfo.videoBase64,
												id: that.maintenanceId,
												type: 1 // 1维保2评估3检测
											};
											that.$http
												.post({
													url: '/maintenance/cutVideoV5',
													data: videoData
												})
												.then(res => {
													if (res
														.code ==
														200 &&
														res
														.success
													) {
														// console.log('后台视频分析返回----', res.data, Math.floor((Math.random()*res.data.length)));
														if (res
															.data
															.length !=
															0
														) {
															that.faceInfo
																.imageBase64 =
																res
																.data[
																	Math
																	.floor(
																		Math
																		.random() *
																		res
																		.data
																		.length
																	)
																]; // 随机取值
															that
																.faceCertificationTwo(); // 调用百度库，进行人脸检测
														} else {
															that.maskBoxState =
																false
															that.loadControl =
																false;
															that.tipsContent =
																'人脸活体视频解析失败, 请重新操作！';
															that.tipsModal =
																true;
														}
													} else {
														that.maskBoxState =
															false
														that.loadControl =
															false;
														that.tipsContent =
															res
															.msg;
														that.tipsModal =
															true;
													}
												});
										},
										fail: () => {
											that.maskBoxState =
												false
											that.loadControl =
												false;
											that.tipsContent =
												'人脸活体视频解析失败, 请重新操作！';
											that.tipsModal =
												true;
										}
									});
								},
								fail() {
									that.maskBoxState = false
									that.loadControl = false;
									that.tipsContent =
										'人脸活体视频解析失败, 请重新操作！';
									that.tipsModal = true;
								}
							});
						} else {
							that.maskBoxState = false
							that.loadControl = false;
						}
					}
				});

			},
			// 开启刷脸---第二步（调用百度库，进行人脸检测）
			faceCertificationTwo() {
				let that = this;
				that.loadingTxt = '活体检测中，请稍候';
				uni.request({
					url: 'https://aip.baidubce.com/oauth/2.0/token', //是真实的接口地址
					data: {
						grant_type: config.baidu_grant_type,
						client_id: config.baidu_client_id, //用你创建的应用的API Key
						client_secret: config.baidu_client_secret //用你创建的应用的Secret Key
					},
					header: {
						'Content-Type': 'application/json'
					},
					success(res) {
						// console.log('获取token---', res);
						that.faceInfo.accessToken = res.data.access_token; //获取到token
						// 活体检测
						uni.request({
							url: 'https://aip.baidubce.com/rest/2.0/face/v3/faceverify?access_token=' +
								res
								.data
								.access_token,
							method: 'POST',
							data: [{
								image: that.faceInfo.imageBase64,
								image_type: 'BASE64'
							}],
							header: {
								'Content-Type': 'application/json'
							},
							success(res) {
								// console.log('活体检测返回数据---------', res);
								if (res.data.error_code == 0 && res.data.result
									.face_liveness >= 0.8) {
									// 人脸库搜索
									that.loadingTxt = '人脸识别中，请稍候';
									uni.request({
										url: 'https://aip.baidubce.com/rest/2.0/face/v3/search?access_token=' +
											that.faceInfo.accessToken,
										method: 'POST',
										data: {
											image: that.faceInfo
												.imageBase64,
											image_type: 'BASE64',
											group_id_list: config
												.baidu_group_id,
											liveness_control: 'NORMAL', // 活体检测控制NONE: 不进行控制LOW:较低的活体要求(高通过率 低攻击拒绝率)NORMAL: 一般的活体要求(平衡的攻击拒绝率, 通过率)HIGH: 较高的活体要求(高攻击拒绝率 低通过率)默认NONE若活体检测结果不满足要求，则返回结果中会提示活体检测失败
											user_id: config
												.baidu_userid_pre +
												that.userInfo
												.userIdCard
										},
										header: {
											'Content-Type': 'application/json'
										},
										success(res) {
											// console.log('上传人脸检测返回数据-------------', res);
											if (
												res.data.error_msg ==
												'SUCCESS' &&
												res.data.result
												.user_list[0]
												.user_id == config
												.baidu_userid_pre +
												that.userInfo
												.userIdCard &&
												res.data.result
												.user_list[0]
												.score > 80
											) {
												that.maskBoxState =
													false
												that.loadControl =
													false;
												if (that.faceInfo
													.faceState ==
													1 || that.faceInfo
													.faceState == 2) {
													that
														.handleMaintenance(); // 开始维保 or 暂停维保
												} else {
													that
														.endHandleMaintenance(); // 结束执业
												}

											} else {
												that.maskBoxState =
													false
												that.loadControl =
													false;
												if (res.data
													.error_code ==
													'222207') {
													uni.showModal({
														title: '认证失败',
														confirmColor: '#3178FF',
														showCancel: false,
														content: '为了提升消防服务执业的效率，消防小程序将进行一次全面的升级。请依次点击【我的】-【比对公安人证信息】进行操作。感谢您的配合！',
														success: function() {}
													});
												} else {
													that.maskBoxState =
														false
													that.loadControl =
														false;
													that.tipsContent =
														'请所属帐号本人认证！';
													that.tipsModal =
														true;
												}
											}
										},
										fail() {
											that.maskBoxState = false
											that.loadControl = false;
											that.tipsContent =
												'出现错误，人脸对比系统异常！';
											that.tipsModal = true;
										}
									});
								} else {
									that.maskBoxState = false
									that.loadControl = false;
									that.tipsContent = '请确保是本人操作！';
									that.tipsModal = true;
								}
							}
						});
					},
					fail() {
						that.$refs.loading.closeLoading();
						that.tipsContent = '出现错误，ai获取token系统异常！';
						that.tipsModal = true;
					}
				});
			},
			// 开始维保or暂停维保------操作
			async handleMaintenance() {
				let that = this;
				that.$refs.loading.openLoading(that.faceInfo.faceState == 1 ? '开启维保中···' :
					'暂停维保中···'); // 打开loading动画
				let filePath = wx.env.USER_DATA_PATH + '/hym_pay_qrcode.png';
				uni.getFileSystemManager().writeFile({
					filePath: filePath, //创建一个临时文件名
					data: that.faceInfo.imageBase64, //写入的文本或二进制数据
					encoding: 'base64', //写入当前文件的字符编码
					success: res => {
						that.$uploadImg.uploadImgOSSBase64(filePath, 4).then(
							resPortrait => {
								if (resPortrait != null && resPortrait
									.length >
									0) {
									if (that.faceInfo.faceState == 1) {
										this.maintenanceParams = {
											maintenanceId: that
												.maintenanceDetails
												.id, // 维保记录ID
											startLatitude: that
												.faceInfo
												.latitude, // 维保开始纬度
											startLongitude: that
												.faceInfo
												.longitude, // 维保开始经度
											startFaceUrl: resPortrait, // 执业人脸认证头像
											openid: that.openid
										};
									} else {
										this.maintenanceParams = {
											maintenanceId: that
												.maintenanceDetails
												.id, // 维保记录ID
											endLatitude: that.faceInfo
												.latitude, // 维保结束纬度
											endLongitude: that.faceInfo
												.longitude, // 维保结束经度
											endFaceUrl: resPortrait, // 执业人脸认证头像
											openid: that.openid
										};
									}

									this.$http
										.post({
											url: that.faceInfo
												.faceState == 1 ?
												'/maintenance/startPractice/V3' :
												'/maintenance/endPractice/V3',
											data: this
												.maintenanceParams
										})
										.then(res => {
											// console.log('执业返回的结果-------------', res);
											that.$refs.loading
												.closeLoading();
											if (res.code == 200 && res
												.success) {
												// 是否疑似违规执业(0:正常 1:疑似违规)
												if (that.faceInfo
													.faceState == 1) {
													// 开始执业
													res.data.forEach(
														item => {
															if (item
																.status ==
																1
															) {
																uni.showModal({
																	title: '',
																	content: item
																		.msg,
																	confirmText: '确定',
																	confirmColor: '#3178FF',
																	showCancel: false,
																	success: res => {
																		if (res
																			.confirm
																		) {
																			that
																				.refreshClick(); // 重新刷新页面
																		}
																	}
																});
															}
														})
													that.tipsContent =
														'开始维保成功！请注意：项目负责人与至少1位执业人员打卡后，才计算有效工时。并且在执业期间随时接受消防救援机构的抽查。';
													that.tipsModal =
														true;
													getApp()
														.getConfigCenter(); // 获取配置信息--并打开定时任务
													that
														.refreshClick(); // 重新刷新页面
												} else if (that
													.faceInfo
													.faceState == 2) {
													// 暂停执业
													if (res.data
														.status == 1) {
														that.tipsContent =
															res.data
															.msg;
														that.tipsModal =
															true;
														that
															.refreshClick(); // 重新刷新页面
													} else {
														that.tipsContent =
															'暂停维保成功！';
														that.tipsModal =
															true;
														getApp()
															.closeScheduledTask(); // 关闭定时任务
														that
															.refreshClick(); // 重新刷新页面
														return;
													}
												}
											} else {
												that.tipsContent = res
													.msg;
												that.tipsModal = true;
											}
										});
								} else {
									that.$refs.loading.closeLoading();
									that.tipsContent = '人脸上传失败，请检查网络是否正常！';
									that.tipsModal = true;
								}
							});
					},
					fail: err => {
						that.$refs.loading.closeLoading();
						// console.log('开始维保发生错误-----', err);
					}
				});
			},
			// 结束执业--------第一步
			endMaintenanceOne() {
				let that = this;
				if (that.maintenanceDetails.canEnd == null || that.maintenanceDetails
					.canEnd ==
					2) {
					that.tipsContent = '当前无法结束执业！';
					that.tipsModal = true;
					return;
				}
				// 检测是否设备图片没有添加
				that.$http.post({
					url: `/maintenance/${that.maintenanceId}/checkFinishPic`
				}).then((res => {
					// console.log('检测是否设备图片没有添加返回----', res)
					if (res.code == 200) {
						that.endMaintenanceTwo()
					} else {
						uni.showModal({
							title: '',
							content: res.msg,
							confirmText: '继续',
							confirmColor: '#3178FF',
							cancelColor: '#606266',
							success: res => {
								if (res.confirm) {
									that.endMaintenanceTwo() // 结束执业---第二步
								}
							}
						});
					}
				}))
			},
			// 结束执业--------第二步
			endMaintenanceTwo() {
				let that = this;
				// 检测本地是否有缓存数据
				let judgeInfo = [];
				// 判断是否有未提交的数据-----缓存
				uni.getStorageSync('allMaintenanceFacilities').forEach(res => {
					if (uni.getStorageSync(res.id)) {
						judgeInfo.push(res.facilitiesTypeName);
					}
				});
				if (judgeInfo.length > 0) {
					uni.showModal({
						title: '温馨提示',
						content: `"${judgeInfo}"有您填写的内容尚未提交，请确认是否结束现场执业？`,
						confirmColor: '#3178FF',
						cancelColor: '#606266',
						success: res => {
							if (res.confirm) {
								// uni.showModal({
								// 	title: '是否结束现场执业？',
								// 	content: '现场执业结束后，不允许再编辑现场维保情况。请确认现场维保情况是否都已经填写。',
								// 	confirmColor: '#3178FF',
								// 	cancelColor: '#606266',
								// 	success: res => {
								// 		if (res.confirm) {
								// 			that.faceInfo.faceState = 3
								// 			that.checkFaceClick(3); // 刷脸前的校验---结束维保
								// 		}
								// 	}
								//});
								that.faceInfo.faceState = 3
								that.checkFaceClick(3); // 刷脸前的校验---结束维保
							}
						}
					});
				} else {
					that.faceInfo.faceState = 3
					that.checkFaceClick(3); // 刷脸前的校验---结束维保
				}
			},
			// 结束执业----第三步
			async endHandleMaintenance() {
				this.$refs.loading.openLoading('结束维保中···');
				const data = await this.$http.post({
					url: `/maintenance/${this.maintenanceDetails.id}/end`
				});
				if (data.code == 200 && data.success) {
					this.tipsContent = '结束维保成功！';
					this.tipsModal = true;
					getApp().closeScheduledTask(); // 关闭定时任务
					this.$pageJump.reLaunch(
						'/pages/maintenance/mechanism/home/components/mechanismWork/components/mechanismResults?id=' +
						this.maintenanceDetails.id +
						'&operators=' +
						JSON.stringify(this.maintenanceDetails.operators)
					);
				} else {
					this.tipsContent = data.msg;
					this.tipsModal = true;
				}
				this.$refs.loading.closeLoading();
			}
		},
		onShareAppMessage() {
			return {
				title: '分享小程序给朋友',
				path: '/pages/homePage/Home'
			};
		}
	};
</script>

<style lang="scss" scoped>
	@import './components/mechanismWorking.scss';

	.maskBox {
		background: rgba(0, 0, 0, 0.3);
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 3;
	}
</style>